﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Frame.Lib.Core.Base;


namespace Cms.DAL.Traffic
{
    public class IPTraficDAL : BaseDAL
    {
        public void Delete(string startTime, string endTime)
        {
            string condition = " 1=1 ";

            if (!string.IsNullOrEmpty(startTime))
            {
                condition += " and InputTime >= @p0";
            }
            if (!string.IsNullOrEmpty(endTime))
            {
                condition += " and InputTime <= @p1";
            }

            string sql = "delete from "+ CTableName.IPTrafic + " where " + condition;

            dbOper.RunSql(sql, startTime, endTime);
        }

        public void Delete()
        {
            string sql = "delete from CmsIP";
            dbOper.RunSql(sql);
        }

        public bool Exist(string ip, DateTime begin, DateTime end)
        {
            string sql = "select count(*) from CmsIP where IP = @p0 and InputTime between @p1 and @p2";
            int count = dbOper.GetScalar<int>(sql, ip, begin, end);
            return count == 0 ? false : true;
        }
    }

}
